﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using WebServer.DBUtility;
using WebServer.Models;

namespace WebServer.DBAccess
{
    public class ArticleDA
    {
        #region 分类逻辑
        /// <summary>
        /// 获取分类
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public List<NewsCate> Cate(int ID, bool IsDel)
        {
            List<NewsCate> request = new List<NewsCate>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_O_Ctae", new object[] { ID, IsDel }))
                {

                    while (reader.Read())
                    {
                        NewsCate entity = new NewsCate();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.Name = reader[1].ToString();
                        if (reader[2] != DBNull.Value)
                            entity.Parent = reader[2].ToInt32();
                        else
                            entity.Parent = 0;
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }



        /// <summary>
        /// 获取存在交易所
        /// </summary>
        /// <returns></returns>
        public List<NewsCate> CateGroup(int Parent, int CenterID)
        {
            List<NewsCate> request = new List<NewsCate>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_O_CateGroup", new object[] { Parent, CenterID }))
                {

                    while (reader.Read())
                    {
                        NewsCate entity = new NewsCate();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.Name = reader[1].ToString();
                        if (reader[2] != DBNull.Value)
                            entity.Parent = reader[2].ToInt32();
                        else
                            entity.Parent = 0;
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 获取分类
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public NewsCate CateByID(int ID)
        {
            NewsCate request = new NewsCate();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_O_Ctae_ByID", new object[] { ID }))
                {

                    while (reader.Read())
                    {
                        if (reader[0] != DBNull.Value)
                            request.ID = reader[0].ToInt32();
                        else
                            request.ID = 0;
                        request.Name = reader[1].ToString();
                        if (reader[2] != DBNull.Value)
                            request.Parent = reader[2].ToInt32();
                        else
                            request.Parent = 0;
                        if (reader[3] != DBNull.Value)
                            request.IsDel = reader[3].ToBoolean();
                        else
                            request.IsDel = false;
                        if (reader[4] != DBNull.Value)
                            request.CreateTime = reader[4].ToDateTime();
                        else
                            request.CreateTime = DateTime.Now;
                        if (reader[5] != DBNull.Value)
                            request.Updatetime = reader[5].ToDateTime();
                        else
                            request.Updatetime = DateTime.Now;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 获取分类
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public bool CateCreate(string Name, int ParentID)
        {
            bool request = false;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_O_Ctae_Create", new object[] { Name, ParentID }))
                {

                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? (reader[0].ToInt32() > 0 ? true : false) : false;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 更新分类
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public bool CateSet(int ID, string Name, int Parent, bool IsDel)
        {
            bool request = false;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_O_Ctae_Set", new object[] { ID, Name, Parent, IsDel }))
                {

                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? (reader[0].ToInt32() > 0 ? true : false) : false;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 获取所有的子分类 
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public List<NewsCate> ManCate(bool IsDel)
        {
            List<NewsCate> request = new List<NewsCate>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_O_Ctae_Q", new object[] { IsDel }))
                {

                    while (reader.Read())
                    {
                        NewsCate entity = new NewsCate();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.Name = reader[1].ToString();
                        if (reader[2] != DBNull.Value)
                            entity.Parent = reader[2].ToInt32();
                        else
                            entity.Parent = 0;
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 获取判断是否有子节点的分类
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public static List<NewsCate> CateList(int ID, bool IsDel)
        {
            List<NewsCate> request = new List<NewsCate>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_O_Cate_Q]", new object[] { ID, IsDel }))
                {

                    while (reader.Read())
                    {
                        NewsCate entity = new NewsCate();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.Name = reader[1].ToString();
                        if (reader[2] != DBNull.Value)
                            entity.Parent = reader[2].ToInt32();
                        else
                            entity.Parent = 0;
                        if (reader[3] != DBNull.Value)
                            entity.childID = reader[3].ToInt32();
                        else
                            entity.childID = 0;
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }
        #endregion


        #region 文章处理


        /// <summary>
        /// 获取文章详情
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public Article ArticleByID(int ID)
        {
            Article request = new Article();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_O_Article_ByID", new object[] { ID }))
                {

                    while (reader.Read())
                    {
                        if (reader[0] != DBNull.Value)
                            request.ID = reader[0].ToInt32();
                        else
                            request.ID = 0;
                        if (reader[1] != DBNull.Value)
                            request.CateID = reader[1].ToInt32();
                        else
                            request.CateID = 0;
                        request.Title = reader[2].ToString();
                        request.SmallTitle = reader[3].ToString();
                        request.Text = reader[4].ToString();
                        if (reader[5] != DBNull.Value)
                            request.IsDel = reader[5].ToBoolean();
                        else
                            request.IsDel = false;
                        if (reader[6] != DBNull.Value)
                            request.UpdateTime = reader[6].ToDateTime();
                        else
                            request.UpdateTime = DateTime.Now;
                        request.Img = reader[7].ToString();
                        if (reader[8] != DBNull.Value)
                            request.Hits = reader[8].ToInt32();
                        else
                            request.Hits = 0;
                        if (reader[9] != DBNull.Value)
                            request.Stick = reader[9].ToBoolean();
                        else
                            request.Stick = false;
                        request.Style = reader[10].ToString();
                        request.CateName = reader[11].ToString();
                        if (reader[12] != DBNull.Value)
                            request.CenterID = reader[12].ToInt32();
                        else
                            request.CenterID = 0;
                        request.Code = reader[13].ToString();
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 获取文章排行
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="Sort">默认根据点击排序，1-修改时间</param>
        /// <returns></returns>
        public List<Article> ArticleBySort(int CateID, int Size, int Sort, bool Desc)
        {
            List<Article> request = new List<Article>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_O_Article_Sort", new object[] { CateID, Size, Sort, Desc }))
                {

                    while (reader.Read())
                    {
                        Article entity = new Article();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        if (reader[1] != DBNull.Value)
                            entity.CateID = reader[1].ToInt32();
                        else
                            entity.CateID = 0;
                        entity.Title = reader[2].ToString();
                        entity.SmallTitle = reader[3].ToString();

                        if (reader[4] != DBNull.Value)
                            entity.Hits = reader[4].ToInt32();
                        else
                            entity.Hits = 0;
                        if (reader[5] != DBNull.Value)
                            entity.UpdateTime = reader[5].ToDateTime();
                        else
                            entity.UpdateTime = DateTime.Now;

                        entity.Img = reader[6].ToString();
                        entity.CateName = reader[7].ToString();

                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 获取文章详情
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public List<Article> ArticleList(int CateID, int Page, int PageSize, int CenterID, string Code, bool HasImg, bool Stick, bool IsDel)
        {
            List<Article> request = new List<Article>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_O_Article_Q", new object[] { CateID, Page, PageSize, CenterID, Code, HasImg, Stick, IsDel }))
                {

                    while (reader.Read())
                    {
                        Article entity = new Article();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        if (reader[1] != DBNull.Value)
                            entity.CateID = reader[1].ToInt32();
                        else
                            entity.CateID = 0;
                        entity.Title = reader[2].ToString();
                        entity.SmallTitle = reader[3].ToString();

                        if (reader[4] != DBNull.Value)
                            entity.Hits = reader[4].ToInt32();
                        else
                            entity.Hits = 0;
                        if (reader[5] != DBNull.Value)
                            entity.UpdateTime = reader[5].ToDateTime();
                        else
                            entity.UpdateTime = DateTime.Now;
                        entity.Img = reader[6].ToString();
                        if (reader[7] != DBNull.Value)
                            entity.CenterID = reader[7].ToInt32();
                        else
                            entity.CenterID = 0;
                        entity.Code = reader[8].ToString();
                        if (reader[9] != DBNull.Value)
                            entity.Stick = reader[9].ToBoolean();
                        else
                            entity.Stick = false;
                        entity.CateName = reader[10].ToString();
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 可以模糊查询百科
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public List<Article> MArticleList(int CateID, int Page, int PageSize, int CenterID, string Code,string Title, bool HasImg, int Stick, int Order,bool Desc,int IsDel)
        {
            List<Article> request = new List<Article>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_O_Article_MQ]", new object[] { CateID, Page, PageSize, CenterID, Code, Title, HasImg, Stick, Order, Desc,IsDel }))
                {

                    while (reader.Read())
                    {
                        Article entity = new Article();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        if (reader[1] != DBNull.Value)
                            entity.CateID = reader[1].ToInt32();
                        else
                            entity.CateID = 0;
                        entity.Title = reader[2].ToString();
                        entity.SmallTitle = reader[3].ToString();

                        if (reader[4] != DBNull.Value)
                            entity.Hits = reader[4].ToInt32();
                        else
                            entity.Hits = 0;
                        if (reader[5] != DBNull.Value)
                            entity.UpdateTime = reader[5].ToDateTime();
                        else
                            entity.UpdateTime = DateTime.Now;
                        entity.Img = reader[6].ToString();
                        if (reader[7] != DBNull.Value)
                            entity.CenterID = reader[7].ToInt32();
                        else
                            entity.CenterID = 0;
                        entity.Code = reader[8].ToString();
                        if (reader[9] != DBNull.Value)
                            entity.Stick = reader[9].ToBoolean();
                        else
                            entity.Stick = false;
                        entity.CateName = reader[10].ToString();
                        entity.CenterName = reader[11].ToString();
                        entity.Fullname = reader[12].ToString();
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 手机查询百科
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public List<Article> PArticleList(int CateID, string OpenTime, string EndTime, int PageSize, int CenterID, string Code, string Title, bool HasImg, int Stick, int Order, bool Desc, int IsDel)
        {
            List<Article> request = new List<Article>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_O_Article_PQ]", new object[] { CateID, OpenTime, EndTime, PageSize, CenterID, Code, Title, HasImg, Stick, Order, Desc, IsDel }))
                {

                    while (reader.Read())
                    {
                        Article entity = new Article();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        if (reader[1] != DBNull.Value)
                            entity.CateID = reader[1].ToInt32();
                        else
                            entity.CateID = 0;
                        entity.Title = reader[2].ToString();
                        entity.SmallTitle = reader[3].ToString();

                        if (reader[4] != DBNull.Value)
                            entity.Hits = reader[4].ToInt32();
                        else
                            entity.Hits = 0;
                        if (reader[5] != DBNull.Value)
                            entity.UpdateTime = reader[5].ToDateTime();
                        else
                            entity.UpdateTime = DateTime.Now;
                        entity.Img = reader[6].ToString();
                        if (reader[7] != DBNull.Value)
                            entity.CenterID = reader[7].ToInt32();
                        else
                            entity.CenterID = 0;
                        entity.Code = reader[8].ToString();
                        if (reader[9] != DBNull.Value)
                            entity.Stick = reader[9].ToBoolean();
                        else
                            entity.Stick = false;
                        entity.CateName = reader[10].ToString();
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }



        /// <summary>
        /// 百科总数
        /// </summary>
        /// <param name="CateID"></param>
        /// <param name="CenterID"></param>
        /// <param name="Code"></param>
        /// <param name="Title"></param>
        /// <param name="HasImg"></param>
        /// <param name="Stick"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public static int MArticleCount(int CateID, int CenterID, string Code, string Title, bool HasImg, int Stick,  int IsDel)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_O_Article_MC]", new object[] { CateID, CenterID, Code, Title, HasImg, Stick, IsDel });
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return 0;
            }
            catch (Exception ex)
            {
                return 0;
            }
        }


        /// <summary>
        /// 文章动作
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public bool ArticleAction(int ID, string Filed, bool Fn)
        {
            bool request = false;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_O_Article_Action", new object[] { ID, Filed, Fn }))
                {

                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? (reader[0].ToInt32() > 0 ? true : false) : false;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }



        /// <summary>
        /// 新增以及更新文章
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public bool ArticleSet(Article N)
        {
            bool request = false;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_O_Article_Set", new object[] { N.ID, N.CateID, N.Title, N.SmallTitle, N.Text, N.Img, N.Style, N.CenterID, N.Code ,N.Hits}))
                {

                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? (reader[0].ToInt32() > 0 ? true : false) : false;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        #endregion

        #region 广告
        /// <summary>
        /// 广告列表
        /// </summary>
        /// <param name="PageSize"></param>
        /// <param name="Page"></param>
        /// <param name="Name"></param>
        /// <param name="Type"></param>
        /// <param name="Img"></param>
        /// <param name="Url"></param>
        /// <param name="Rank"></param>
        /// <param name="Place"></param>
        /// <param name="Dtlimit"></param>
        /// <param name="Order">默认根据rank排序，1-ID，2-开始时间，3-结束时间</param>
        /// <param name="Desc"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public static List<WebAd> AdSearch(int PageSize, int Page, string Name, string Type, string Img, string Url, int Rank, string Place, DateTime Dtlimit, int AppOrWeb, int Order, bool Desc, bool IsDel)
        {
            List<WebAd> entitys = new List<WebAd>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object[] tiaoj = new object[] { PageSize, (Page - 1) * PageSize, Name, Type, Img, Url, Rank, Place, Dtlimit, Order, Desc, IsDel,AppOrWeb };
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_N_Ad_Q]", tiaoj))
                {
                    WebAd entity = null;
                    while (reader.Read())
                    {
                        entity = new WebAd();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.Name = reader[1].ToString();
                        entity.Type = reader[2].ToString();
                        entity.Img = reader[3].ToString();
                        entity.Url = reader[4].ToString();
                        if (reader[5] != DBNull.Value)
                            entity.Rank = reader[5].ToInt32();
                        else
                            entity.Rank = 0;
                        entity.MarketTime = reader[6].ToString();
                        entity.LogoutTime = reader[7].ToString();
                        entity.Place = reader[8].ToString();
                        if (reader[9] != DBNull.Value)
                            entity.Hits = reader[9].ToInt32();
                        else
                            entity.Hits = 0;
                        entitys.Add(entity);
                    }

                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }

            return entitys;
        }


        /// <summary>
        /// 广告列表-区分是否过期
        /// </summary>
        /// <param name="PageSize"></param>
        /// <param name="Page"></param>
        /// <param name="Type"></param>
        /// <param name="Rank"></param>
        /// <param name="Place"></param>
        /// <param name="IsOverdue"></param>
        /// <param name="Order"></param>
        /// <param name="Desc"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public static List<WebAd> AdList(int PageSize, int Page, string Type, int Rank, string Place, int IsOverdue,int AppOrWeb, int Order, bool Desc, bool IsDel)
        {
            List<WebAd> entitys = new List<WebAd>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object[] tiaoj = new object[] { PageSize, (Page - 1) * PageSize, Type, Rank, Place, IsOverdue, AppOrWeb, Order, Desc, IsDel };
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_N_Ad_QIsOverdue]", tiaoj))
                {
                    WebAd entity = null;
                    while (reader.Read())
                    {
                        entity = new WebAd();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.Name = reader[1].ToString();
                        entity.Type = reader[2].ToString();
                        entity.Img = reader[3].ToString();
                        entity.Url = reader[4].ToString();
                        if (reader[5] != DBNull.Value)
                            entity.Rank = reader[5].ToInt32();
                        else
                            entity.Rank = 0;
                        entity.MarketTime = reader[6].ToString();
                        entity.LogoutTime = reader[7].ToString();
                        entity.Place = reader[8].ToString();
                        if (reader[9] != DBNull.Value)
                            entity.Hits = reader[9].ToInt32();
                        else
                            entity.Hits = 0;
                        if (reader[10] != DBNull.Value)
                            entity.AppOrWeb = reader[10].ToInt32();
                        else
                            entity.AppOrWeb = 0;
                        entitys.Add(entity);
                    }

                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }

            return entitys;
        }


        /// <summary>
        /// 广告列表-区分是否过期
        /// </summary>
        /// <param name="PageSize"></param>
        /// <param name="Page"></param>
        /// <param name="Type"></param>
        /// <param name="Rank"></param>
        /// <param name="Place"></param>
        /// <param name="IsOverdue"></param>
        /// <param name="Order"></param>
        /// <param name="Desc"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public static List<WebAd> MAdList(int PageSize, int Page, string Type, int Rank, string Place, string Keys, int IsOverdue, int AppOrWeb, int Order, bool Desc, bool IsDel)
        {
            List<WebAd> entitys = new List<WebAd>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object[] tiaoj = new object[] { PageSize, (Page - 1) * PageSize, Type, Rank, Place, Keys, IsOverdue, AppOrWeb, Order, Desc, IsDel };
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_N_Ad_MQ]", tiaoj))
                {
                    WebAd entity = null;
                    while (reader.Read())
                    {
                        entity = new WebAd();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.Name = reader[1].ToString();
                        entity.Type = reader[2].ToString();
                        entity.Img = reader[3].ToString();
                        entity.Url = reader[4].ToString();
                        if (reader[5] != DBNull.Value)
                            entity.Rank = reader[5].ToInt32();
                        else
                            entity.Rank = 0;
                        entity.MarketTime = reader[6].ToString();
                        entity.LogoutTime = reader[7].ToString();
                        entity.Place = reader[8].ToString();
                        if (reader[9] != DBNull.Value)
                            entity.Hits = reader[9].ToInt32();
                        else
                            entity.Hits = 0;
                        if (reader[10] != DBNull.Value)
                            entity.AppOrWeb = reader[10].ToInt32();
                        else
                            entity.AppOrWeb = 0;
                        entitys.Add(entity);
                    }

                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }

            return entitys;
        }



      /// <summary>
        /// 广告总数-区分是否过期
      /// </summary>
      /// <param name="Type"></param>
      /// <param name="Rank"></param>
      /// <param name="Place"></param>
      /// <param name="IsOverdue"></param>
      /// <param name="IsDel"></param>
      /// <returns></returns>
        public static int AdCount(string Type, int Rank, string Place,string Keys, int IsOverdue,int AppOrWeb, bool IsDel)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object[] tiaoj = new object[] { Type, Rank, Place, Keys, IsOverdue, AppOrWeb, IsDel };
                object obj = sqlHelp.ExecuteSPScalar("[sp_N_Ad_MC]", tiaoj);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }




         /// <summary>
        /// 删除广告
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static int DelAd(int ID)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_N_Ad_D]", ID);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// 新增或者修改广告
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int AddOrUpAd(WebAd model)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object[] WhereInfo = new object[] { model.ID, model.Name, model.Type, model.Img, model.Url, model.Rank, model.MarketTime, model.LogoutTime, model.Place, model.AppOrWeb ,model.Keys};

                //object[] WhereInfo = new object[] { 67, "中南", "Link", "http://imgs.17ybk.com/link/zhongnan.jpg", "http://www.znypjy.com/", 1, "2016-01-01", "2099-01-01", "img", 2 };

                object obj = sqlHelp.ExecuteSPScalar("[sp_N_Ad_Set]", WhereInfo);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// 根据ID获取广告
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static WebAd AdByID(int ID)
        {
            WebAd entity = new WebAd();
            try
            {

                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_N_Ad_ByID]", ID))
                {
                    while (reader.Read())
                    {

                        entity = new WebAd();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.Name = reader[1].ToString();
                        entity.Type = reader[2].ToString();
                        entity.Img = reader[3].ToString();
                        entity.Url = reader[4].ToString();
                        if (reader[5] != DBNull.Value)
                            entity.Rank = reader[5].ToInt32();
                        else
                            entity.Rank = 0;
                        entity.MarketTime = reader[6].ToString();
                        entity.LogoutTime = reader[7].ToString();
                        entity.Place = reader[8].ToString();
                        if (reader[9] != DBNull.Value)
                            entity.Hits = reader[9].ToInt32();
                        else
                            entity.Hits = 0;
                        if (reader[10] != DBNull.Value)
                            entity.AppOrWeb = reader[10].ToInt32();
                        else
                            entity.AppOrWeb = 0;
                        entity.Keys = reader[11].ToString();
                    }

                    reader.Close();
                }

            }
            catch (Exception ex)
            {
            }
            return entity;
        }
        #endregion

        #region 广告
        /// <summary>
        /// 广告列表
        /// </summary>
        /// <param name="PageSize"></param>
        /// <param name="Page"></param>
        /// <param name="Name"></param>
        /// <param name="Type"></param>
        /// <param name="Img"></param>
        /// <param name="Url"></param>       
        /// <param name="Place"></param>      
        /// <param name="Order">默认根据ID排序，1-Place</param>
        /// <param name="Desc"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public static List<APPAd> PAdSearch(int PageSize, int Page, string Img, string Type, string Name, string Place, int Order, bool Desc, bool IsDel)
        {
            List<APPAd> entitys = new List<APPAd>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object[] tiaoj = new object[] { PageSize, (Page - 1) * PageSize, Img, Type, Name, Place, Order, Desc, IsDel};
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_N_P_Ad_Q]", tiaoj))
                {
                    APPAd entity = null;
                    while (reader.Read())
                    {
                        entity = new APPAd();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.Img = reader[1].ToString();
                        entity.Text = reader[2].ToString();
                        entity.Type = reader[3].ToString();
                        entity.Name = reader[4].ToString();
                        entity.Url = reader[5].ToString();
                        entity.MarketTime = reader[6].ToString();
                        entity.LogoutTime = reader[7].ToString();
                        entity.Place = reader[8].ToString();
                        entitys.Add(entity);
                    }

                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }

            return entitys;
        }


        /// <summary>
        /// 广告总数-区分是否过期
        /// </summary>
        /// <param name="Type"></param>
        /// <param name="Rank"></param>
        /// <param name="Place"></param>
        /// <param name="IsOverdue"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public static int PAdCount(string Img, string Type, string Name, string Place,  bool IsDel)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object[] tiaoj = new object[] { Img, Type, Name, Place, IsDel };
                object obj = sqlHelp.ExecuteSPScalar("[sp_N_P_Ad_MC]", tiaoj);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }




        /// <summary>
        /// 删除广告
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static int PDelAd(int ID)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_N_P_Ad_D]", ID);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// 新增或者修改广告
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int PAddOrUpAd(APPAd model)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object[] WhereInfo = new object[] { model.ID, model.Img, model.Text, model.Type, model.Name, model.Url,model.Place, model.MarketTime, model.LogoutTime };

                object obj = sqlHelp.ExecuteSPScalar("[sp_N_P_Ad_Set]", WhereInfo);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// 根据ID获取广告
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static APPAd PAdByID(int ID)
        {
            APPAd entity = new APPAd();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_N_P_Ad_ByID]", ID))
                {
                    while (reader.Read())
                    {
                        entity = new APPAd();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.Img = reader[1].ToString();
                        entity.Text = reader[2].ToString();
                        entity.Type = reader[3].ToString();
                        entity.Name = reader[4].ToString();
                        entity.Url = reader[5].ToString();
                        entity.MarketTime = reader[6].ToString();
                        entity.LogoutTime = reader[7].ToString();
                        entity.Place = reader[8].ToString();
                    }

                    reader.Close();
                }

            }
            catch (Exception ex)
            {
            }
            return entity;
        }
        #endregion

        #region 特殊页面
        /// <summary>
        /// 特殊页面列表-区分是否过期
        /// </summary>
        /// <param name="PageSize"></param>
        /// <param name="Page"></param>
        /// <param name="Type"></param>
        /// <param name="Rank"></param>
        /// <param name="Place"></param>
        /// <param name="IsOverdue"></param>
        /// <param name="Order"></param>
        /// <param name="Desc"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public static List<SpecialPage> SpecialPageList(int PageSize, int Page, string Name, int Order, bool Desc, bool IsDel)
        {
            List<SpecialPage> entitys = new List<SpecialPage>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object[] tiaoj = new object[] { PageSize, (Page - 1) * PageSize, Name, Order, Desc, IsDel };
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_N_SpecialPage_QIsOverdue]", tiaoj))
                {
                    SpecialPage entity = null;
                    while (reader.Read())
                    {
                        entity = new SpecialPage();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.Name = reader[1].ToString();
                        entity.Text = reader[2].ToString();
                        entity.Img = reader[3].ToString();
                        entity.Url = reader[4].ToString();                  
                        if (reader[5] != DBNull.Value)
                            entity.Hits = reader[5].ToInt32();
                        else
                            entity.Hits = 0;
                        entitys.Add(entity);
                    }

                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }

            return entitys;
        }
        
 
        /// <summary>
        /// 特殊页面列表-区分是否过期
        /// </summary>
        /// <param name="Type"></param>
        /// <param name="Rank"></param>
        /// <param name="Place"></param>
        /// <param name="IsOverdue"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public static int SpecialCount(string Name, bool IsDel)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object[] tiaoj = new object[] { Name, IsDel };
                object obj = sqlHelp.ExecuteSPScalar("[sp_N_SpecialPage_Count]", tiaoj);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return 0;
            }
            catch (Exception ex)
            {
                return 0;
            }
        }

        /// <summary>
        /// 删除特殊页面
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static int DelSpecial(int ID)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_N_SpecialPage_D]", ID);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// 新增或者修改广告
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int AddOrUpSpecial(SpecialPage model)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object[] WhereInfo = new object[] { model.ID, model.Name, model.Text, model.Img, model.Url };

                object obj = sqlHelp.ExecuteSPScalar("[sp_N_SpecialPage_Set]", WhereInfo);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// 根据ID获取广告
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static SpecialPage SpecialByID(int ID)
        {
            SpecialPage entity = new SpecialPage();
            try
            {

                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_N_SpecialPage_ByID]", ID))
                {
                    while (reader.Read())
                    {

                        entity = new SpecialPage();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.Name = reader[1].ToString();
                        entity.Text = reader[2].ToString();
                        entity.Img = reader[3].ToString();
                        entity.Url = reader[4].ToString();                       
                        if (reader[5] != DBNull.Value)
                            entity.Hits = reader[5].ToInt32();
                        else
                            entity.Hits = 0;
                    }

                    reader.Close();
                }

            }
            catch (Exception ex)
            {
            }
            return entity;
        }
        #endregion


        #region 申购日历
        /// <summary>
        /// 申购月份统计
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public List<PurchaseTotalEntity> PurchaseTotal(DateTime Begin, DateTime End)
        {
            List<PurchaseTotalEntity> request = new List<PurchaseTotalEntity>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_O_PurchaseTotal", new object[] { Begin, End }))
                {
                    while (reader.Read())
                    {
                        PurchaseTotalEntity entity = new PurchaseTotalEntity();
                        if (reader[0] != DBNull.Value)
                            entity.Days = reader[0].ToDateTime();
                        else
                            entity.Days = DateTime.Now;
                        entity.CateName = reader[1].ToString();
                        if (reader[2] != DBNull.Value)
                            entity.Nums = reader[2].ToInt32();
                        else
                            entity.Nums = 0;
                        //if (reader[3] != DBNull.Value)
                        //    entity.EndffectTime = reader[3].ToDateTime();
                        //else
                        //    entity.EndffectTime = DateTime.Now;
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 申购月份数据
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public List<Purchase> Purchase(DateTime Begin, DateTime End)
        {
            List<Purchase> request = new List<Purchase>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_O_Purchase", new object[] { Begin, End }))
                {
                    while (reader.Read())
                    {
                        Purchase entity = new Purchase();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.CateName = reader[1].ToString();
                        if (reader[2] != DBNull.Value)
                            entity.EffectTime = reader[2].ToDateTime();
                        else
                            entity.EffectTime = DateTime.Now;
                        if (reader[3] != DBNull.Value)
                            entity.CenterID = reader[3].ToInt32();
                        else
                            entity.CenterID = 0;
                        entity.CenterName = reader[4].ToString();
                        entity.Code = reader[5].ToString();
                        entity.Fullname = reader[6].ToString();
                        if (reader[7] != DBNull.Value)
                            entity.OnlinePrice = reader[7].ToDecimal();
                        else
                            entity.OnlinePrice = 0;

                        if (reader[8] != DBNull.Value)
                            entity.UpAmount = reader[8].ToInt32();
                        else
                            entity.UpAmount = 0;
                        if (reader[9] != DBNull.Value)
                            entity.BuyAmount = reader[9].ToInt32();
                        else
                            entity.BuyAmount = 0;

                        if (reader[10] != DBNull.Value)
                            entity.Amount = reader[10].ToInt32();
                        else
                            entity.Amount = 0;
                        //if (reader[11] != DBNull.Value)
                        //    entity.MaxAmount = reader[11].ToInt32();
                        //else
                        //    entity.MaxAmount = 0;
                        entity.MaxAmount = reader[11].ToString();


                        if (reader[12] != DBNull.Value)
                            entity.CodesTime = reader[12].ToDateTime();
                        else
                            entity.CodesTime = DateTime.Now;
                        if (reader[13] != DBNull.Value)
                            entity.OnlineTime = reader[13].ToDateTime();
                        else
                            entity.OnlineTime = DateTime.Now;
                        entity.Ratio = reader[14].ToString();
                        entity.BuyType = reader[15].ToString();
                        entity.Link = reader[16].ToString();
                        entity.Remark = reader[17].ToString();
                        if (reader[18] != DBNull.Value)
                            entity.CreateTime = reader[18].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;
                        entity.RatioVal = reader[19].ToString();
                        if (reader[20] != DBNull.Value)
                            entity.TotalPrice = reader[20].ToDecimal();
                        else
                            entity.TotalPrice =5000000000;
                         if (reader[21] != DBNull.Value)
                             entity.TotalValue = reader[21].ToDecimal();
                        else
                             entity.TotalValue = 0;
                         if (reader[22] != DBNull.Value)
                             entity.EndffectTime = reader[22].ToDateTime();
                         else
                             entity.EndffectTime = DateTime.Now;
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 申购月份数据
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public List<Purchase> PurchasePolish(DateTime Begin, DateTime End, bool polish)
        {
            List<Purchase> request = new List<Purchase>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_O_Purchase_POQ", new object[] { Begin, End ,polish}))
                {
                    while (reader.Read())
                    {
                        Purchase entity = new Purchase();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.CateName = reader[1].ToString();
                        if (reader[2] != DBNull.Value)
                            entity.EffectTime = reader[2].ToDateTime();
                        else
                            entity.EffectTime = DateTime.Now;
                        if (reader[3] != DBNull.Value)
                            entity.CenterID = reader[3].ToInt32();
                        else
                            entity.CenterID = 0;
                        entity.CenterName = reader[4].ToString();
                        entity.Code = reader[5].ToString();
                        entity.Fullname = reader[6].ToString();
                        if (reader[7] != DBNull.Value)
                            entity.OnlinePrice = reader[7].ToDecimal();
                        else
                            entity.OnlinePrice = 0;

                        if (reader[8] != DBNull.Value)
                            entity.UpAmount = reader[8].ToInt32();
                        else
                            entity.UpAmount = 0;
                        if (reader[9] != DBNull.Value)
                            entity.BuyAmount = reader[9].ToInt32();
                        else
                            entity.BuyAmount = 0;

                        if (reader[10] != DBNull.Value)
                            entity.Amount = reader[10].ToInt32();
                        else
                            entity.Amount = 0;
                        //if (reader[11] != DBNull.Value)
                        //    entity.MaxAmount = reader[11].ToInt32();
                        //else
                        //    entity.MaxAmount = 0;
                        entity.MaxAmount = reader[11].ToString();


                        if (reader[12] != DBNull.Value)
                            entity.CodesTime = reader[12].ToDateTime();
                        else
                            entity.CodesTime = DateTime.Now;
                        if (reader[13] != DBNull.Value)
                            entity.OnlineTime = reader[13].ToDateTime();
                        else
                            entity.OnlineTime = DateTime.Now;
                        entity.Ratio = reader[14].ToString();
                        entity.BuyType = reader[15].ToString();
                        entity.Link = reader[16].ToString();
                        entity.Remark = reader[17].ToString();
                        if (reader[18] != DBNull.Value)
                            entity.CreateTime = reader[18].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;
                        entity.RatioVal = reader[19].ToString();
                        if (reader[20] != DBNull.Value)
                            entity.TotalPrice = reader[20].ToDecimal();
                        else
                            entity.TotalPrice = 5000000000;
                        if (reader[21] != DBNull.Value)
                            entity.TotalValue = reader[21].ToDecimal();
                        else
                            entity.TotalValue = 0;
                        if (reader[22] != DBNull.Value)
                            entity.EndffectTime = reader[22].ToDateTime();
                        else
                            entity.EndffectTime = DateTime.Now;
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 申购月份数据
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public List<Purchase> MPurchaseList(int PageSize, int PageIndex, int CenterID, string BeginTime, string EndTime,string Cate, int Order, bool Desc)
        {
            List<Purchase> request = new List<Purchase>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_O_Purchase_MQ]", new object[] { PageSize, (PageIndex - 1) * PageSize, CenterID, BeginTime, EndTime, Cate, Order, Desc }))
                {
                    while (reader.Read())
                    {
                        Purchase entity = new Purchase();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.CateName = reader[1].ToString();
                        if (reader[2] != DBNull.Value)
                            entity.EffectTime = reader[2].ToDateTime();
                        else
                            entity.EffectTime = DateTime.Now;
                        if (reader[3] != DBNull.Value)
                            entity.CenterID = reader[3].ToInt32();
                        else
                            entity.CenterID = 0;
                        entity.CenterName = reader[4].ToString();
                        entity.Code = reader[5].ToString();
                        entity.Fullname = reader[6].ToString();
                        if (reader[7] != DBNull.Value)
                            entity.OnlinePrice = reader[7].ToDecimal();
                        else
                            entity.OnlinePrice = 0;

                        if (reader[8] != DBNull.Value)
                            entity.UpAmount = reader[8].ToInt32();
                        else
                            entity.UpAmount = 0;
                        if (reader[9] != DBNull.Value)
                            entity.BuyAmount = reader[9].ToInt32();
                        else
                            entity.BuyAmount = 0;

                        if (reader[10] != DBNull.Value)
                            entity.Amount = reader[10].ToInt32();
                        else
                            entity.Amount = 0;
                        //if (reader[11] != DBNull.Value)
                        //    entity.MaxAmount = reader[11].ToInt32();
                        //else
                        //    entity.MaxAmount = 0;
                        entity.MaxAmount = reader[11].ToString();


                        if (reader[12] != DBNull.Value)
                            entity.CodesTime = reader[12].ToDateTime();
                        else
                            entity.CodesTime = DateTime.Now;
                        if (reader[13] != DBNull.Value)
                            entity.OnlineTime = reader[13].ToDateTime();
                        else
                            entity.OnlineTime = DateTime.Now;
                        entity.Ratio = reader[14].ToString();
                        entity.BuyType = reader[15].ToString();
                        entity.Link = reader[16].ToString();
                        entity.Remark = reader[17].ToString();
                        if (reader[18] != DBNull.Value)
                            entity.CreateTime = reader[18].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;
                        entity.RatioVal = reader[19].ToString();
                        if (reader[20] != DBNull.Value)
                            entity.TotalPrice = reader[20].ToDecimal();
                        else
                            entity.TotalPrice = 5000000000;
                        if (reader[21] != DBNull.Value)
                            entity.TotalValue = reader[21].ToDecimal();
                        else
                            entity.TotalValue = 0;
                        if (reader[22] != DBNull.Value)
                            entity.EndffectTime = reader[22].ToDateTime();
                        else
                            entity.EndffectTime = DateTime.Now;
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 申购月份数据
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public List<Purchase> PurchaseList(int PageSize,int PageIndex,int CenterID,string BeginTime,string EndTime,int Order,bool Desc)
        {
            List<Purchase> request = new List<Purchase>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_O_Purchase_Q]", new object[] { PageSize, (PageIndex - 1) * PageSize, CenterID, BeginTime, EndTime, Order, Desc }))
                {
                    while (reader.Read())
                    {
                        Purchase entity = new Purchase();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.CateName = reader[1].ToString();
                        if (reader[2] != DBNull.Value)
                            entity.EffectTime = reader[2].ToDateTime();
                        else
                            entity.EffectTime = DateTime.Now;
                        if (reader[3] != DBNull.Value)
                            entity.CenterID = reader[3].ToInt32();
                        else
                            entity.CenterID = 0;
                        entity.CenterName = reader[4].ToString();
                        entity.Code = reader[5].ToString();
                        entity.Fullname = reader[6].ToString();
                        if (reader[7] != DBNull.Value)
                            entity.OnlinePrice = reader[7].ToDecimal();
                        else
                            entity.OnlinePrice = 0;

                        if (reader[8] != DBNull.Value)
                            entity.UpAmount = reader[8].ToInt32();
                        else
                            entity.UpAmount = 0;
                        if (reader[9] != DBNull.Value)
                            entity.BuyAmount = reader[9].ToInt32();
                        else
                            entity.BuyAmount = 0;

                        if (reader[10] != DBNull.Value)
                            entity.Amount = reader[10].ToInt32();
                        else
                            entity.Amount = 0;
                        //if (reader[11] != DBNull.Value)
                        //    entity.MaxAmount = reader[11].ToInt32();
                        //else
                        //    entity.MaxAmount = 0;
                        entity.MaxAmount = reader[11].ToString();


                        if (reader[12] != DBNull.Value)
                            entity.CodesTime = reader[12].ToDateTime();
                        else
                            entity.CodesTime = DateTime.Now;
                        if (reader[13] != DBNull.Value)
                            entity.OnlineTime = reader[13].ToDateTime();
                        else
                            entity.OnlineTime = DateTime.Now;
                        entity.Ratio = reader[14].ToString();
                        entity.BuyType = reader[15].ToString();
                        entity.Link = reader[16].ToString();
                        entity.Remark = reader[17].ToString();
                        if (reader[18] != DBNull.Value)
                            entity.CreateTime = reader[18].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;
                        entity.RatioVal = reader[19].ToString();
                        if (reader[20] != DBNull.Value)
                            entity.TotalPrice = reader[20].ToDecimal();
                        else
                            entity.TotalPrice = 5000000000;
                        if (reader[21] != DBNull.Value)
                            entity.TotalValue = reader[21].ToDecimal();
                        else
                            entity.TotalValue = 0;
                        if (reader[22] != DBNull.Value)
                            entity.EndffectTime = reader[22].ToDateTime();
                        else
                            entity.EndffectTime = DateTime.Now;
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }
        
        /// <summary>
        /// 获取申购日历总数
        /// </summary>
        /// <param name="CenterID"></param>
        /// <param name="BeginTime"></param>
        /// <param name="EndTime"></param>
        /// <returns></returns>
        public int PurchaseCount(int CenterID, string BeginTime, string EndTime, string Cate)
        {
            try
            {
                object[] whereInfo = new object[] { CenterID, BeginTime, EndTime, Cate };
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_O_Purchase_MC]", whereInfo);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return 0;
            }
            catch (Exception ex)
            {
                return 0;
            }
        }

        /// <summary>
        /// 申购月份数据
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public List<Purchase> PurchaseNews(string CateName)
        {
            List<Purchase> request = new List<Purchase>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                DateTime da = DateTime.Parse(DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + " 00:00:00");

                using (IDataReader reader = sqlHelp.ExecuteReader("sp_O_PurchaseNews", new object[] { da, CateName }))
                {
                    while (reader.Read())
                    {
                        Purchase entity = new Purchase();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.CateName = reader[1].ToString();
                        if (reader[2] != DBNull.Value)
                            entity.EffectTime = reader[2].ToDateTime();
                        else
                            entity.EffectTime = DateTime.Now;
                        if (reader[3] != DBNull.Value)
                            entity.CenterID = reader[3].ToInt32();
                        else
                            entity.CenterID = 0;
                        entity.CenterName = reader[4].ToString();
                        entity.Code = reader[5].ToString();
                        entity.Fullname = reader[6].ToString();
                        if (reader[7] != DBNull.Value)
                            entity.OnlinePrice = reader[7].ToDecimal();
                        else
                            entity.OnlinePrice = 0;

                        if (reader[8] != DBNull.Value)
                            entity.UpAmount = reader[8].ToInt32();
                        else
                            entity.UpAmount = 0;
                        if (reader[9] != DBNull.Value)
                            entity.BuyAmount = reader[9].ToInt32();
                        else
                            entity.BuyAmount = 0;

                        if (reader[10] != DBNull.Value)
                            entity.Amount = reader[10].ToInt32();
                        else
                            entity.Amount = 0;
                        //if (reader[11] != DBNull.Value)
                        //    entity.MaxAmount = reader[11].ToInt32();
                        //else
                        //    entity.MaxAmount = 0;

                        entity.MaxAmount = reader[11].ToString();
                        if (reader[12] != DBNull.Value)
                            entity.CodesTime = reader[12].ToDateTime();
                        else
                            entity.CodesTime = DateTime.Now;
                        if (reader[13] != DBNull.Value)
                            entity.OnlineTime = reader[13].ToDateTime();
                        else
                            entity.OnlineTime = DateTime.Now;
                        entity.Ratio = reader[14].ToString();
                        entity.BuyType = reader[15].ToString();
                        entity.Link = reader[16].ToString();
                        entity.Remark = reader[17].ToString();
                        if (reader[18] != DBNull.Value)
                            entity.CreateTime = reader[18].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;
                        entity.RatioVal = reader[19].ToString();
                        if (reader[20] != DBNull.Value)
                            entity.TotalPrice = reader[20].ToDecimal();
                        else
                            entity.TotalPrice = 5000000000;
                        if (reader[21] != DBNull.Value)
                            entity.TotalValue = reader[21].ToDecimal();
                        else
                            entity.TotalValue = 0;
                        if (reader[22] != DBNull.Value)
                            entity.EndffectTime = reader[22].ToDateTime();
                        else
                            entity.EndffectTime = DateTime.Now;
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 申购月份数据
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public List<Purchase> PurchaseNewsTwo(DateTime Begin, DateTime End,string CateName)
        {
            List<Purchase> request = new List<Purchase>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_O_Purchase_News]", new object[] { Begin, End, CateName }))
                {
                    while (reader.Read())
                    {
                        Purchase entity = new Purchase();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.CateName = reader[1].ToString();
                        if (reader[2] != DBNull.Value)
                            entity.EffectTime = reader[2].ToDateTime();
                        else
                            entity.EffectTime = DateTime.Now;
                        if (reader[3] != DBNull.Value)
                            entity.CenterID = reader[3].ToInt32();
                        else
                            entity.CenterID = 0;
                        entity.CenterName = reader[4].ToString();
                        entity.Code = reader[5].ToString();
                        entity.Fullname = reader[6].ToString();
                        if (reader[7] != DBNull.Value)
                            entity.OnlinePrice = reader[7].ToDecimal();
                        else
                            entity.OnlinePrice = 0;

                        if (reader[8] != DBNull.Value)
                            entity.UpAmount = reader[8].ToInt32();
                        else
                            entity.UpAmount = 0;
                        if (reader[9] != DBNull.Value)
                            entity.BuyAmount = reader[9].ToInt32();
                        else
                            entity.BuyAmount = 0;

                        if (reader[10] != DBNull.Value)
                            entity.Amount = reader[10].ToInt32();
                        else
                            entity.Amount = 0;
                        //if (reader[11] != DBNull.Value)
                        //    entity.MaxAmount = reader[11].ToInt32();
                        //else
                        //    entity.MaxAmount = 0;
                        entity.MaxAmount = reader[11].ToString();

                        if (reader[12] != DBNull.Value)
                            entity.CodesTime = reader[12].ToDateTime();
                        else
                            entity.CodesTime = DateTime.Now;
                        if (reader[13] != DBNull.Value)
                            entity.OnlineTime = reader[13].ToDateTime();
                        else
                            entity.OnlineTime = DateTime.Now;
                        entity.Ratio = reader[14].ToString();
                        entity.BuyType = reader[15].ToString();
                        entity.Link = reader[16].ToString();
                        entity.Remark = reader[17].ToString();
                        if (reader[18] != DBNull.Value)
                            entity.CreateTime = reader[18].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;
                        entity.RatioVal = reader[19].ToString();
                        if (reader[20] != DBNull.Value)
                            entity.TotalPrice = reader[20].ToDecimal();
                        else
                            entity.TotalPrice = 5000000000;
                        if (reader[21] != DBNull.Value)
                            entity.TotalValue = reader[21].ToDecimal();
                        else
                            entity.TotalValue = 0;
                        if (reader[22] != DBNull.Value)
                            entity.EndffectTime = reader[22].ToDateTime();
                        else
                            entity.EndffectTime = DateTime.Now;
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 申购月份数据
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public Purchase PurchaseByID(int ID)
        {
            Purchase  entity = new Purchase();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_O_Purchase_ByID", new object[] { ID }))
                {
                    while (reader.Read())
                    {
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.CateName = reader[1].ToString();
                        if (reader[2] != DBNull.Value)
                            entity.EffectTime = reader[2].ToDateTime();
                        else
                            entity.EffectTime = DateTime.Now;
                        if (reader[3] != DBNull.Value)
                            entity.CenterID = reader[3].ToInt32();
                        else
                            entity.CenterID = 0;
                        entity.CenterName = reader[4].ToString();
                        entity.Code = reader[5].ToString();
                        entity.Fullname = reader[6].ToString();
                        if (reader[7] != DBNull.Value)
                            entity.OnlinePrice = reader[7].ToDecimal();
                        else
                            entity.OnlinePrice = 0;

                        if (reader[8] != DBNull.Value)
                            entity.UpAmount = reader[8].ToInt32();
                        else
                            entity.UpAmount = 0;
                        if (reader[9] != DBNull.Value)
                            entity.BuyAmount = reader[9].ToInt32();
                        else
                            entity.BuyAmount = 0;

                        if (reader[10] != DBNull.Value)
                            entity.Amount = reader[10].ToInt32();
                        else
                            entity.Amount = 0;
                        //if (reader[11] != DBNull.Value)
                        //    entity.MaxAmount = reader[11].ToInt32();
                        //else
                        //    entity.MaxAmount = 0;
                        entity.MaxAmount = reader[11].ToString();

                        if (reader[12] != DBNull.Value)
                            entity.CodesTime = reader[12].ToDateTime();
                        else
                            entity.CodesTime = DateTime.Now;
                        if (reader[13] != DBNull.Value)
                            entity.OnlineTime = reader[13].ToDateTime();
                        else
                            entity.OnlineTime = DateTime.Now;
                        entity.Ratio = reader[14].ToString();
                        entity.BuyType = reader[15].ToString();
                        entity.Link = reader[16].ToString();
                        entity.Remark = reader[17].ToString();
                        if (reader[18] != DBNull.Value)
                            entity.CreateTime = reader[18].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;
                        entity.RatioVal = reader[19].ToString();
                        if (reader[20] != DBNull.Value)
                            entity.TotalPrice = reader[20].ToDecimal();
                        else
                            entity.TotalPrice = 5000000000;
                        if (reader[21] != DBNull.Value)
                            entity.TotalValue = reader[21].ToDecimal();
                        else
                            entity.TotalValue = 0;
                        if (reader[22] != DBNull.Value)
                            entity.EndffectTime = reader[22].ToDateTime();
                        else
                            entity.EndffectTime = DateTime.Now;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return entity;
        }

        /// <summary>
        /// 添加或修改投资日历
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static int PurchaseSet(Purchase entity)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object[] WhereInfo = new object[] { entity.ID, entity.CateName, entity.EffectTime, entity.CenterID, entity.CenterName, entity.Code, entity.Fullname, entity.OnlinePrice, entity.UpAmount, entity.BuyAmount, entity.Amount, entity.MaxAmount, entity.CodesTime, entity.OnlineTime, entity.Ratio, entity.BuyType, entity.Link, entity.Remark, entity.RatioVal, entity.TotalPrice,entity.TotalValue,entity.EndffectTime };
                object obj = sqlHelp.ExecuteSPScalar("[sp_O_Purchase_Set]", WhereInfo);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }


        /// <summary>
        /// 改藏品的总申购资金 单签资金 单签持仓
        /// </summary>
        /// <returns></returns>
        public int PurchaseListed(PurchaseListed entity)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object[] WhereInfo = new object[] { entity.ID, entity.PurchaseTotal, entity.DqPrice, entity.Dqposition };
                object obj = sqlHelp.ExecuteSPScalar("[sp_O_Purchase_AddListed]", WhereInfo);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }


        /// <summary>
        /// 获取藏品的总申购资金 单签资金 单签持仓
        /// </summary>
        /// <returns></returns>
        public PurchaseListed PurchaseListedByID(int ID)
        {
            PurchaseListed entity = new PurchaseListed();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_O_Purchase_ListedByID", new object[] { ID }))
                {
                    while (reader.Read())
                    {
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        if (reader[1] != DBNull.Value)
                            entity.PurchaseTotal = reader[1].ToDecimal();
                        else
                            entity.PurchaseTotal = 0;
                        if (reader[2] != DBNull.Value)
                            entity.DqPrice = reader[2].ToDecimal();
                        else
                            entity.DqPrice = 0;
                        if (reader[3] != DBNull.Value)
                            entity.Dqposition = reader[3].ToDecimal();
                        else
                            entity.Dqposition = 0;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return entity;
        }



        /// <summary>
        /// 删除申购日历
        /// </summary>
        /// <param name="ID">邮吧ID</param>
        /// <param name="Filed">列名</param>
        /// <param name="Fn">值</param>
        /// <returns></returns>
        public static int PurchaseAction(int ID, string Filed, bool Fn)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object[] WhereInfo = new object[] { ID, Filed, Fn };
                object obj = sqlHelp.ExecuteSPScalar("[sp_O_Purchase_Action]", WhereInfo);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// 手機查詢打新助手
        /// </summary>
        /// <param name="OpenTime"></param>
        /// <returns></returns>
        public static List<PpurchaseTotalEntity> PPurchaseTotal(DateTime OpenTime)
        {
            List<PpurchaseTotalEntity> request = new List<PpurchaseTotalEntity>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_O_PurchasePTotal]", new object[] { OpenTime }))
                {
                    while (reader.Read())
                    {
                        PpurchaseTotalEntity entity = new PpurchaseTotalEntity();
                        entity.CenterName = reader[0].ToString();                       
                        entity.CateName = reader[1].ToString();
                        if (reader[2] != DBNull.Value)
                            entity.Nums = reader[2].ToInt32();
                        else
                            entity.Nums = 0;
                        if (reader[3] != DBNull.Value)
                            entity.CenterID = reader[3].ToInt32();
                        else
                            entity.CenterID = 0;
                        if (OpenTime != null)
                            entity.SearchTime = OpenTime;
                        else
                            entity.SearchTime = DateTime.Now;
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;

        }
        #endregion


        #region 新闻专题
        /// <summary>
        /// 新闻专题
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static Project ProjectByID(int ID)
        {
            Project request = new Project();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_P_ProjectByID]", new object[] { ID }))
                {
                    while (reader.Read())
                    {
                        if (reader[0] != DBNull.Value)
                            request.ID = reader[0].ToInt32();
                        else
                            request.ID = 0;
                        request.Title = reader[1].ToString();
                        request.Description = reader[2].ToString();
                        request.KeyWords = reader[3].ToString();
                        request.Img = reader[4].ToString();
                        if (reader[5] != DBNull.Value)
                            request.CenterID = reader[5].ToInt32();
                        else
                            request.CenterID = 0;
                        request.Code = reader[6].ToString();
                        request.Keys = reader[7].ToString();
                        if (reader[8] != DBNull.Value)
                            request.BarID = reader[8].ToInt32();
                        else
                            request.BarID = 0;
                        if (reader[9] != DBNull.Value)
                            request.BeginTime = reader[9].ToDateTime();
                        else
                            request.BeginTime = DateTime.Now;
                        if (reader[10] != DBNull.Value)
                            request.CreateTime = reader[10].ToDateTime();
                        else
                            request.CreateTime = DateTime.Now;
                        if (reader[11] != DBNull.Value)
                            request.IsDel = reader[11].ToBoolean();
                        else
                            request.IsDel = true;
                        request.AdImg = reader[12].ToString();
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;

        }
        /// <summary>
        /// 新闻专题幻灯片
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static List<ProjectSilder> ProjectSilderByPID(int ID)
        {
            List<ProjectSilder> request = new List<ProjectSilder>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_P_ProjectSilderByPID]", new object[] { ID }))
                {
                    while (reader.Read())
                    {
                        ProjectSilder one = new ProjectSilder();
                        if (reader[0] != DBNull.Value)
                            one.ID = reader[0].ToInt32();
                        else
                            one.ID = 0;
                        if (reader[1] != DBNull.Value)
                            one.PID = reader[1].ToInt32();
                        else
                            one.PID = 0;
                        one.Img = reader[2].ToString();
                        one.Title = reader[3].ToString();
                        one.Text = reader[4].ToString();
                        one.Url = reader[5].ToString();
                        if (reader[6] != DBNull.Value)
                            one.Sort = reader[6].ToInt32();
                        else
                            one.Sort = 0;
                        if (reader[7] != DBNull.Value)
                            one.CreateTime = reader[7].ToDateTime();
                        else
                            one.CreateTime = DateTime.Now;
                        request.Add(one);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;

        }
        /// <summary>
        /// 新闻专题时间轴
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static List<ProjectTimeEntity> ProjectTimeByPID(int ID)
        {
            List<ProjectTimeEntity> request = new List<ProjectTimeEntity>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_P_ProjectTimeByPID]", new object[] { ID }))
                {
                    while (reader.Read())
                    {
                        ProjectTimeEntity one = new ProjectTimeEntity();
                        if (reader[0] != DBNull.Value)
                            one.ID = reader[0].ToInt32();
                        else
                            one.ID = 0;
                        if (reader[1] != DBNull.Value)
                            one.PID = reader[1].ToInt32();
                        else
                            one.PID = 0;
                        if (reader[2] != DBNull.Value)
                            one.CurTime = reader[2].ToDateTime();
                        else
                            one.CurTime = DateTime.Now;
                        one.Title = reader[3].ToString();
                        one.Url = reader[4].ToString();
                        if (reader[5] != DBNull.Value)
                            one.CreateTime = reader[5].ToDateTime();
                        else
                            one.CreateTime = DateTime.Now;
                        request.Add(one);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;

        }
        /// <summary>
        /// 新闻专题时间轴
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static List<News> ProjectNewsByID(int PID)
        {
            List<News> request = new List<News>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_P_ProjectNewsByPID]", new object[] { PID }))
                {
                    while (reader.Read())
                    {
                        News entity = new News();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        if (reader[1] != DBNull.Value)
                            entity.CateID = reader[1].ToInt32();
                        else
                            entity.CateID = 0;
                        entity.Title = reader[2].ToString();
                        entity.SmallTitle = reader[3].ToString();

                        if (reader[4] != DBNull.Value)
                            entity.Hits = reader[4].ToInt32();
                        else
                            entity.Hits = 0;
                        entity.Shortened = reader[5].ToString();
                        entity.Name = reader[6].ToString();
                        if (reader[7] != DBNull.Value)
                            entity.CreateTime = reader[7].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;

                        entity.Img = reader[8].ToString();
                        if (reader[9] != DBNull.Value)
                            entity.Retotal = reader[9].ToInt32();
                        else
                            entity.Retotal = 0;
                        if (reader[10] != DBNull.Value)
                            entity.Commend = reader[10].ToBoolean();
                        else
                            entity.Commend = false;
                        if (reader[11] != DBNull.Value)
                            entity.Stick = reader[11].ToBoolean();
                        else
                            entity.Stick = false;
                        if (reader[12] != DBNull.Value)
                            entity.IsHeadline = reader[12].ToBoolean();
                        else
                            entity.IsHeadline = false;
                        if (reader[13] != DBNull.Value)
                            entity.IsPush = reader[13].ToBoolean();
                        else
                            entity.IsPush = false;
                        entity.CateName = reader[14].ToString();
                        if (reader[16] != DBNull.Value)
                            entity.PNID = reader[16].ToInt32();
                        else
                            entity.PNID = 0;
                        if (reader[17] != DBNull.Value)
                            entity.UserCateID = reader[17].ToInt32();
                        else
                            entity.UserCateID = 0;
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;

        }
        /// <summary>
        /// 添加专题
        /// </summary>
        /// <param name="Entity"></param>
        /// <returns></returns>
        public int AddProject(Project Entity)
        {
            try
            {
                object[] whereInfo = new object[] { Entity.ID, Entity.Title, Entity.Description, Entity.KeyWords, Entity.Img, Entity.CenterID, Entity.Code, Entity.Keys, Entity.BarID, Entity.BeginTime, Entity.AdImg };
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_P_ProjectSet]", whereInfo);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }



        /// <summary>
        /// 专题列表
        /// </summary>
        /// <param name="PageSize"></param>
        /// <param name="PageIndex"></param>
        /// <param name="OrderID"></param>
        /// <param name="Desc"></param>
        /// <returns></returns>
        public List<Project> ProjectList(int PageSize, int PageIndex, int OrderID, bool Desc, bool IsDel)
        {

            List<Project> request = new List<Project>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_P_Project_Q]", new object[] { PageSize, (PageIndex - 1) * PageSize, OrderID, Desc, IsDel }))
                {
                    while (reader.Read())
                    {
                        Project one = new Project();
                        if (reader[0] != DBNull.Value)
                            one.ID = reader[0].ToInt32();
                        else
                            one.ID = 0;

                        one.Title = reader[1].ToString();
                        one.Description = reader[2].ToString();
                        one.KeyWords = reader[3].ToString();
                        one.Img = reader[4].ToString();
                        one.Keys = reader[7].ToString();
                        if (reader[8] != DBNull.Value)
                            one.BarID = reader[8].ToInt32();
                        else
                            one.BarID = 0;
                        if (reader[9] != DBNull.Value)
                            one.BeginTime = reader[9].ToDateTime();
                        else
                            one.BeginTime = DateTime.Now;
                        if (reader[10] != DBNull.Value)
                            one.CreateTime = reader[10].ToDateTime();
                        else
                            one.CreateTime = DateTime.Now;
                        one.AdImg = reader[12].ToString();

                        request.Add(one);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }



        /// <summary>
        /// 专题列表-第一个新闻的图片
        /// </summary>
        /// <param name="PageSize"></param>
        /// <param name="PageIndex"></param>
        /// <param name="OrderID"></param>
        /// <param name="Desc"></param>
        /// <returns></returns>
        public List<Project> ProjectListImg(int PageSize, int PageIndex, int OrderID, bool Desc, bool IsDel)
        {

            List<Project> request = new List<Project>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_P_Project_NewsImgQ]", new object[] { PageSize, (PageIndex - 1) * PageSize, OrderID, Desc, IsDel }))
                {
                    while (reader.Read())
                    {
                        Project one = new Project();
                        if (reader[0] != DBNull.Value)
                            one.ID = reader[0].ToInt32();
                        else
                            one.ID = 0;

                        one.Title = reader[1].ToString();
                        one.Description = reader[2].ToString();
                        one.KeyWords = reader[3].ToString();
                        one.Img = reader[4].ToString();
                        one.Keys = reader[7].ToString();
                        if (reader[8] != DBNull.Value)
                            one.BarID = reader[8].ToInt32();
                        else
                            one.BarID = 0;
                        if (reader[9] != DBNull.Value)
                            one.BeginTime = reader[9].ToDateTime();
                        else
                            one.BeginTime = DateTime.Now;
                        if (reader[10] != DBNull.Value)
                            one.CreateTime = reader[10].ToDateTime();
                        else
                            one.CreateTime = DateTime.Now;

                        request.Add(one);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 专题总数
        /// </summary>
        /// <returns></returns>
        public int ProjectCount(bool IsDel)
        {
            try
            {
                object[] whereInfo = new object[] { IsDel };
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_P_Project_C]", whereInfo);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }


        /// <summary>
        /// 添加或取消新闻
        /// </summary>
        /// <returns></returns>
        public int PNewsSet(int ID,int PID,int NewID,int Sort)
        {
            try
            {
                object[] whereInfo = new object[] { ID, PID, NewID, Sort };
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_P_NewsSet]", whereInfo);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

       /// <summary>
        /// 添加或修改幻灯片
        /// </summary>
        /// <returns></returns>
        public int PSildeSet(ProjectSilder entity)
        {
            try
            {
                object[] whereInfo = new object[] { entity.ID, entity.PID, entity.Img, entity.Title, entity.Text, entity.Url, entity.Sort };
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_P_SilderSet]", whereInfo);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// 根据ID获取专题幻灯片
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public ProjectSilder SildeByID(int ID)
        {
            ProjectSilder request = new ProjectSilder();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_P_ProjectSilderByID]", new object[] { ID }))
                {
                    while (reader.Read())
                    {
                        if (reader[0] != DBNull.Value)
                            request.ID = reader[0].ToInt32();
                        else
                            request.ID = 0;
                        if (reader[1] != DBNull.Value)
                            request.PID = reader[1].ToInt32();
                        else
                            request.PID = 0;
                        request.Img = reader[2].ToString();
                        request.Title = reader[3].ToString();
                        request.Text = reader[4].ToString();
                        request.Url = reader[5].ToString();
                        if (reader[6] != DBNull.Value)
                            request.Sort = reader[6].ToInt32();
                        else
                            request.Sort = 0;
                        if (reader[7] != DBNull.Value)
                            request.CreateTime = reader[7].ToDateTime();
                        else
                            request.CreateTime = DateTime.Now;
                       
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }



        /// <summary>
        /// shanchu 幻灯片
        /// </summary>
        /// <returns></returns>
        public int DelPSilde(int ID)
        {
            try
            {
                object[] whereInfo = new object[] { ID };
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_P_ProjectSilderD]", whereInfo);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }


        /// <summary>
        /// shanchu时间戳
        /// </summary>
        /// <returns></returns>
        public int DelPTime(int ID)
        {
            try
            {
                object[] whereInfo = new object[] { ID };
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_P_TimeD]", whereInfo);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// 根据Id获取时间戳
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public ProjectTimeEntity PTimeByID(int ID)
        {
             ProjectTimeEntity request = new ProjectTimeEntity();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_P_TimeByID]", new object[] { ID }))
                {
                    while (reader.Read())
                    {                       
                        if (reader[0] != DBNull.Value)
                            request.ID = reader[0].ToInt32();
                        else
                            request.ID = 0;
                        if (reader[1] != DBNull.Value)
                            request.PID = reader[1].ToInt32();
                        else
                            request.PID = 0;
                        if (reader[2] != DBNull.Value)
                            request.CurTime = reader[2].ToDateTime();
                        else
                            request.CurTime = DateTime.Now;
                        request.Title = reader[3].ToString();
                        request.Url = reader[4].ToString();
                        if (reader[5] != DBNull.Value)
                            request.CreateTime = reader[5].ToDateTime();
                        else
                            request.CreateTime = DateTime.Now;                       
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


          /// <summary>
        /// 添加或修改时间戳
        /// </summary>
        /// <returns></returns>
        public int PTimeSet(ProjectTimeEntity entity)
        {
            try
            {
                object[] whereInfo = new object[] { entity.ID, entity.PID, entity.CurTime, entity.Title, entity.Url };
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_P_TimeSet]", whereInfo);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }


        /// <summary>
        /// 删除专题
        /// </summary>
        /// <returns></returns>
        public int ProjectD(int ID)
        {
            try
            {
                object[] whereInfo = new object[] { ID };
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_P_ProjectD]", whereInfo);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }
        #endregion

    }
}
